class CmsController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max) params.max = 10
        [ cmsList: Cms.list( params ) ]
    }

    def show = {
        def cms = Cms.get( params.id )

        if(!cms) {
            flash.message = "Cms not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ cms : cms ] }
    }

    def delete = {
        def cms = Cms.get( params.id )
        if(cms) {
            cms.delete()
            flash.message = "Cms ${params.id} deleted"
            redirect(action:list)
        }
        else {
            flash.message = "Cms not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def cms = Cms.get( params.id )

        if(!cms) {
            flash.message = "Cms not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ cms : cms ]
        }
    }

    def update = {
        def cms = Cms.get( params.id )
        if(cms) {
            cms.properties = params
            if(!cms.hasErrors() && cms.save()) {
                flash.message = "Cms ${params.id} updated"
                redirect(action:show,id:cms.id)
            }
            else {
                render(view:'edit',model:[cms:cms])
            }
        }
        else {
            flash.message = "Cms not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def cms = new Cms()
        cms.properties = params
        return ['cms':cms]
    }

    def save = {
        def cms = new Cms(params)
        if(!cms.hasErrors() && cms.save()) {
            flash.message = "Cms ${cms.id} created"
            redirect(action:show,id:cms.id)
        }
        else {
            render(view:'create',model:[cms:cms])
        }
    }
}
